﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Collections;
using Com.Crc.PoJo.Model.Resource;
using SnailGame.Utility.DataAccess;
namespace Com.Crc.ResManage.DAL.EquipManage
{
    public class UMPASSPORTManagerDAL
    {

        DataBroker broker = new DataBroker();
        /// <summary>
        /// 查询帐号信息，已经路id对应的上一个级别的Id
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public System.Data.DataTable queryAccountInfo(String account)
        {
            String sql = "select t.* ,(select isNull(a.s_up,-1)+'|'+isNull(a.s_down,-1)+'|'+cast(a.N_ID as varchar) from dbo.TT_RESOURCE_AREA a where a.S_TYPE = 6007 and a.N_ID = t.N_AREA_ID and a.S_STATE='1') S_AREA_ID_INFO from dbo.um_passport t where t.s_account='" + account + "'";
            return broker.ExecuteQueryForOleDB(sql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        public bool add(UM_PASSPORT data)
        {
            string strSql = @" INSERT INTO UM_PASSPORT( S_ACCOUNT,N_IN_TYPE,N_STATION_ID,S_DK,S_NAME,S_TEL,S_ADDRESS_TYPE,N_AREA_ID,S_ADDRESS,N_PORT, N_IN_AREA,S_ORG_ACCOUNT,D_CREATE,S_STATE) VALUES (" + "'" + data.S_ACCOUNT + "'" + "," + data.N_IN_TYPE + "," + data.N_STATION_ID + "," + "'" + data.S_DK + "'" + "," + "'" + data.S_NAME + "'" + "," + "'" + data.S_TEL + "'" + "," + "'" + data.S_ADDRESS_TYPE + "'" + "," + data.N_AREA_ID + "," + "'" + data.S_ADDRESS + "'" + "," + data.N_PORT + "," + data.N_IN_AREA + "," + "'" + data.S_ORG_ACCOUNT + "'" + ", GETDATE()," + "'1'" + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        public bool modify(UM_PASSPORT data)
        {
            string strSql = @" UPDATE UM_PASSPORT SET N_IN_TYPE=" + data.N_IN_TYPE + @",N_STATION_ID=" + data.N_STATION_ID + @",S_DK='" + data.S_DK + @"',S_NAME='"+data.S_NAME +"' ,S_TEL='" + data.S_TEL + @"',S_ADDRESS_TYPE='" + data.S_ADDRESS_TYPE + @"',N_AREA_ID=" + data.N_AREA_ID + @",S_ADDRESS='" + data.S_ADDRESS + @"',N_PORT=" + data.N_PORT + @",N_IN_AREA=" + data.N_IN_AREA + @",S_ORG_ACCOUNT='" + data.S_ORG_ACCOUNT + @"' WHERE S_ACCOUNT='" + data.S_ACCOUNT + "'";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        public bool modifyAccount(UM_PASSPORT data)
        {
            string strSql = @" UPDATE UM_PASSPORT SET S_ACCOUNT='" + data.S_ACCOUNT + @"' WHERE S_ACCOUNT='" + data.S_ORG_ACCOUNT + "'";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        public bool remove(string account)
        {
            string strSql = "UPDATE UM_PASSPORT SET S_STATE='2' WHERE S_ACCOUNT=" + account;
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        public bool isexist(string account)
        {
            System.Data.DataTable dt = queryAccountInfo(account);
            return dt.Rows.Count != 0;
        }
    }
}
